/**
 *
 */
package com.engine.Mangers;

import java.util.List;

import org.hibernate.Session;

import com.util.AWFLogger;
import com.util.EngineUtil;
import com.wfe.db.SessionUtil;
import com.wfe.db.WorkFlowEngineQueryUtil;
import com.wfe.mapping.client.WfProjectTask;

/**
 * @author Kareem.Yehya
 * @since 30 March 2009 <br>
 *        Use this Engine for GUI tasks which collected for a long time
 * 
 * <br>
 *        This Class Resposible for:- <br>
 * <br>
 *        1- Get non processed actions <br>
 *        2- Select Plan Assosiated with the Action <br>
 *        3- call Project manger to create new project <br>
 * 
 */
public class RepareGUITasks implements Runnable
{
	// @SuppressWarnings("deprecation")
	public void run()
	{

		try
		{
			while(true)
			{
				System.out.println("Enter Repare Tasks main Thread");
				try
				{
					// Session session = SessionUtil.getCurrentSession();
					Session session = SessionUtil.getSession();
					List<WfProjectTask> tasks = WorkFlowEngineQueryUtil.getWfProjectTaskIsProcessedNotHaveEndTime(session);
					if(tasks.size() > 0)
					{
						for(WfProjectTask wfProjectTask : tasks)
						{
							System.out.println("task to be repared = " + wfProjectTask.getRecid());
							wfProjectTask.setIsProcessed(false);
							wfProjectTask.setStartTime(null);
							session.update(wfProjectTask);
							System.out.println("updated");
						}
						// session.beginTransaction().commit();
						EngineUtil.closeSession(session);
					}
				}catch(Exception e)
				{
					AWFLogger.error(e.getMessage());
					e.printStackTrace();
				}
				Thread.sleep(1000);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}

	}

	public static void main(String args[])
	{
		(new Thread(new RepareGUITasks())).start();
	}

}
